package com.wisdytech.common.hbase.config;


import org.apache.hadoop.hbase.HBaseConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.hadoop.hbase.HbaseTemplate;

@Configuration
@EnableConfigurationProperties(HbaseProperties.class)
@ConditionalOnClass(HbaseTemplate.class)
public class HbaseAutoConfiguration {

    private static final String HBASE_QUORUM = "hbase.zookeeper.quorum";
    private static final String HBASE_PORT = "hbase.zookeeper.property.clientPort";


    @Autowired
    private HbaseProperties hbaseProperties;


    @Bean
    public HbaseTemplate hbaseTemplate() {
        HbaseTemplate hbaseTemplate = new HbaseTemplate();
        org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
        conf.set(HBASE_QUORUM, hbaseProperties.getQuorum());
        conf.set(HBASE_PORT, hbaseProperties.getClientPort());
        hbaseTemplate.setConfiguration(conf);
        hbaseTemplate.setAutoFlush(true);
        hbaseTemplate.afterPropertiesSet();
        return hbaseTemplate;
    }


}
